﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kakeibo.Controller {
    class SummaryPanelController : IController{
        private Model.KakeiboDatabase db_;
        private View.SummaryPanel summaryPanel_;

        public SummaryPanelController(Model.KakeiboDatabase db) {
            db_ = db;
            summaryPanel_ = new View.SummaryPanel();
            summaryPanel_.SetAmountColumnHeadersAsMonthly(2012, 7);
            summaryPanel_.OnPanelSizeChanged += this.OnPanelSizeChanged;

            {
                string sql = "select id, parent_category_id, name from category";
                var rows = db_.ReadData(sql);
                foreach (var item in rows) {
                    summaryPanel_.AddRow((string)item[2], (int)(long)item[0], (int)(long)item[1]);
                }
            }
        }

        public View.IView View {
            get { return summaryPanel_; }
        }


        // event handler
        private void OnPanelSizeChanged(object sender, EventArgs e) {
            summaryPanel_.FitAmountColumnsToTreeViewSize();
        }
    }
}
